package com.fulihui.weixinsdk.request.material;

import com.alibaba.fastjson.JSON;
import com.fulihui.weixinsdk.http.HttpMethodEnum;
import com.fulihui.weixinsdk.request.WeixinRequest;
import com.fulihui.weixinsdk.result.material.MaterialMpNewsGetSingleResult;
import com.google.gson.Gson;
import lombok.Data;

import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;

/**
 * 获取单个素材请求-仅针对图文素材
 *
 * @author wang_wx
 * @date 2018-08-01
 */
@Data
public class MaterialMpNewsGetSingleReuest extends WeixinRequest<MaterialMpNewsGetSingleResult> {

    private transient String access_token;

    private String media_id;

    @Override
    public Map<String, String> urlParam() {
        Map<String, String> param = new TreeMap<String, String>();
        if (!Objects.isNull(access_token)) {
            param.put("access_token", access_token);
        }
        return param;
    }

    @Override
    protected void childParam() {

    }

    @Override
    public String service() {
        return "https://api.weixin.qq.com/cgi-bin/material/get_material";
    }

    @Override
    public String urlEndStr() {
        return null;
    }

    @Override
    public MaterialMpNewsGetSingleResult parseResult(String respStr) {
        return new Gson().fromJson(respStr, MaterialMpNewsGetSingleResult.class);
    }

    @Override
    public HttpMethodEnum httpMethod() {
        return HttpMethodEnum.POST;
    }

    @Override
    public String requestData() {
        return JSON.toJSONString(this);
    }
}
